﻿using System;
using System.IO;
using System.Net;
using System.Xml.Serialization;

namespace WoodRobotics.Weather.ModelView
{
    
    public class IP
    {
        
        #region Fields
        private AsyncCallback m_Target;
        #endregion
        
        #region Properties
        public ORM.dnstools IpInfo;
        #endregion
        
        #region Events
        private void IPResponse(IAsyncResult Responce)
        {
            
            HttpWebRequest l_WebRequest = (HttpWebRequest)Responce.AsyncState;
            HttpWebResponse l_WebResponce = (HttpWebResponse)l_WebRequest.EndGetResponse(Responce);
            
            IpInfo = (ORM.dnstools)new XmlSerializer(typeof(ORM.dnstools)).Deserialize(new StreamReader(l_WebResponce.GetResponseStream()));
            
            m_Target.Invoke(null);
            
        }
        #endregion
        
        #region Methods
        public void BeginIPLookup(AsyncCallback Target)
        {
            
            m_Target = Target;
            
            HttpWebRequest l_WebRequest = WebRequest.Create("http://www.domaintools.com/research/my-ip/myip.xml/") as HttpWebRequest;
            l_WebRequest.BeginGetResponse(new AsyncCallback(IPResponse), l_WebRequest);
            
        } 
        #endregion
        
    }
    
}